<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width initial-scale=1.0 maximum-scale=2.0 user-scalable=yes"/>
    <title>我的主页</title>
    <link rel="stylesheet" type="text/css" href="fontawesome/css/font-awesome.css">
    <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
    <title>Title</title>
</head>
<body>


<div class="container">
    <div id="output" class="row" style="height: 50px;"></div>
    <div class="row">
        <div class="col-md-12 column">
            <form id="form" class="form-horizontal" method="post">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title" style="height: 40px;line-height: 40px;">
                            添加
                        </h3>
                    </div>
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-md-1 column">
                            </div>
                            <div class="col-md-8 column">
                                <div class="form-group">
                                    <label for="inputName" class="col-sm-2 control-label">姓名：</label>
                                    <div class="col-sm-10">
                                        <input type="text" name="name" class="form-control" id="inputName" required/>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="inputAge" class="col-sm-2 control-label">年龄：</label>
                                    <div class="col-sm-10">
                                        <input type="number" name="age" class="form-control" id="inputAge" min="16"
                                               max="88" value="18" required/>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-3 column">
                            </div>
                        </div>
                    </div>
                    <div class="panel-footer">
                        <div class="row">
                            <div class="col-md-5 column">
                            </div>
                            <div class="col-md-7 column">
                                <button type="submit" class="btn btn-primary btn-default">提 交</button>
                                <a class="btn btn-default" href="datatables-server.html">取 消</a>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<script type="text/javascript" src="datatables/js/jquery.js"></script>
<script type="text/javascript" src="form/jquery.form.js"></script>
<script type="text/javascript" src="layer/layer.js"></script>
<script type="text/javascript">
    $(function () {

        /**
         * 转换 form为 ajax方式提交
         */
        $('#form').submit(function () {
            $(this).ajaxSubmit({
                // target: '#output',
                url: 'datatables/add2',
                type: 'post',
                dataType: 'json',
                beforeSubmit: function (formData, jqForm, options) {
                    console.log(formData);
                    console.log(jqForm);
                    console.log(options);
                    var queryString = $.param(formData);
                    console.log(queryString);
                    return true;
                },
                success: function (data) {
                    console.log(data);
                    layer.msg(data.message);
                }
            });
            return false;
        });

    });
</script>

</body>
</html>